<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class mostdownloadweek  extends widgets{
    //put your code here
    public function __construct() {
        parent::widgets();
    }
    
    function run($condition = array(), $limit = 10){
		$data =array();
		$data['mostdownloads'] = $this->gets($condition, $limit);
        return $this->build('index',$data);
    }
	
	function gets($condition = array(), $limit = 10) {
		$this->db->select("count(p.SOFT_ID) as totaldownload, p.SOFT_ID, s.*, c.*");
		$this->db->from("logdownload as p");
		$this->db->join("soft as s","p.SOFT_ID = s.SOFT_ID");
		$this->db->join("category as c","c.CAT_ID = s.CAT_ID");
		if($limit >0)
			$this->db->limit($limit);
		if($condition != array())
			$this->db->where($condition);
		$this->db->group_by("p.SOFT_ID");
		$this->db->order_by("totaldownload desc");
		return $this->db->get()->result();

	}
}

?>
